﻿@model IEnumerable<Article>
@{
    Ajax.Dna().Widget()
        .Preview(@<text>
        <p>
          @Html.Global("RES_PREVIEW_NOTSUPPORT")
        </p>
        </text>)
           .Content(@<text>
    @if (Model.Count() > 0)
    {
        var context = WebSiteContext.Current;
        var web = context.Web;

        foreach (var art in Model)
        {
            var article = new ArticleWrapper(art);
            if (!article.IsVisible(Context))
            {
                continue;
            }

            var tags = article.AllTaggs();
            var _content = article.GetGlobalizationContent();
        <h1 class="dna-post-title">
            <a href="@article.PermaLink">@_content.Title</a>
        </h1>
        <hr />
        <ul class="d-horizontal-list">
            @if (tags.Length > 0)
            {
                <li>
                    @Ajax.Dna().Link("javascript:void(0);").LocText("publishing", "Tags").ImageIcons(Url.Content("~/Content/Images/tag_green_16.png")).GetHtml()
                </li>
                foreach (var tag in tags)
                {
                <li>
                    @Publishing.TagLink(tag)
                </li>
                }
            }
            <li>
                @Ajax.Dna().Link("javascript:void(0);").LocText("publishing", "FiledUnder").ImageIcons(Url.Content("~/Content/Images/icon_cat_16.gif")).GetHtml()
            </li>
            @{ var cats = article.AllCategories();}
            @foreach (var cat in cats)
            { 
                <li>
                    @if (cat.IsRoot)
                    {
                        @Ajax.Dna().Link(cat.PermaLink).LocText("publishing", "Uncategorized").GetHtml()
                    }
                    else
                    {
                        @Ajax.Dna().Link(cat.PermaLink).Text(cat.Title).GetHtml()
                    }
                </li>
            }
        </ul>
            if (string.IsNullOrEmpty(article.Password) || (Request.IsAuthenticated && (User.Identity.Name.Equals(article.Author.UserName, StringComparison.OrdinalIgnoreCase))))
            {
        <div class="d-post-body">
            @if (article.ContentFormat == 2)
            {
                @TextEngine.Wiki(_content.Body, topicCssClass: "d-topic")
            }
            else
            { 
                @MvcHtmlString.Create(_content.Body)
            }
            <p>
                &nbsp;</p>
            <hr />
            <table style="width: 100%;">
                <tr>
                    <td style="width: 60px;">
                        <div class="d-avatar">
                            <img src="@article.Author.GetAvatar(60)" width="60" height="60" alt="avatar" /></div>
                        @Html.UserLink(art.UserName)
                    </td>
                    <td style="vertical-align: top;">
                        <ul class="d-horizontal-list">
                            <li>@Ajax.Dna().Link("javascript:void(0);").Text(Html.Global(article.Posted)).ImageIcons(Url.Content("~/Content/Images/calendar_16.png")).GetHtml()</li>
                            <li>@Ajax.Dna().Rating("ViewRatings" + article.ID.ToString()).Value(Convert.ToInt16(article.Ratings)).Changed("$.post('" + Url.Action("Vote", "Article", new { Area = "publishing" }) + "',{id:'" + article.ID + "',value:value});").GetHtml()</li>
                            <li>@Html.Global("publishing","Votes") (@article.TotalVotes)</li>
                            <li>@Ajax.Dna().Link("javascript:void(0);").LocText("publishing", "Reads").ImageIcons(Url.Content("~/Content/Images/notes.gif")).GetHtml()<span>(@article.TotalReads)</span></li>
                            <li>@Ajax.Dna().Link(article.PermaLink + "#commentlist").LocText("publishing", "Comments").ImageIcons(Url.Content("~/Content/Images/comments.gif")).GetHtml()<span>(@article.Comments.Count)</span></li>
                            <li>@Ajax.Dna().Link(Url.Action("Edit", "Article", new { website = web.Name, id = article.ID, Area = "Publishing" })).LocText("RES_EDIT").ImageIcons(Url.Content("~/Content/Images/edit_page.png")).GetHtml()</li>
                        </ul>
                    </td>
                </tr>
            </table>
        </div>
            }
            else
            {
@* Locked post *@
        <table>
            <tr>
                <td>
                    <img src="@Url.Content("~/content/images/icon_lock_48.png")" alt="icon lock" />
                </td>
                <td>
                    @Html.Global("publishing", "PasswordProtection")
                </td>
            </tr>
        </table>
            }
        }
        Html.RegisterStartupScript("var _topic=$('.d-topic'); if (_topic.length) { _topic.dtree(); _topic.before(\"<b>" + Html.Global("RES_CONTENTTABLE") + "</b>\");}");
    }
    else
    { 
        <div class="ui-state-highlight" style="padding: 10px;">
          @Html.Global("publishing", "NoArticles")
        </div>
    }
    </text>)
           .Render();
}
